package com.scalar.chiptrack.operations.dataentry.actions;

import java.util.HashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.scalar.chiptrack.ChipTrackExtendedAction;
import com.scalar.chiptrack.commons.SessionKeys;
import com.scalar.chiptrack.operations.dataentry.actionCommands.DieBankBinningInfoActionCommandFactory;

/**
 * User: Murali Krishna Yengala
 * Date: Jul 22, 2005
 * Time: 4:28:12 PM
 */
public class DieBankBinningInfoAction extends ChipTrackExtendedAction{

    public ActionForward executeRequest( ActionMapping mapping, ActionForm form,
                                         HttpServletRequest request, HttpServletResponse response) throws Exception
    {
        HashMap errors              = ( HashMap ) request.getAttribute( ERROR_MESSAGES );
        HashMap info                = ( HashMap ) request.getAttribute( INFO_MESSAGES );
        String action = request.getParameter("action");
        ActionForward actionForward = mapping.findForward( "dieBankBinningInfoEntry" );

        action = action == null ? "dieBankBinningInfo" : action.trim();
        action = "".equals(action) ? "dieBankBinningInfo" : action;
        try
        {
            ChipTrackExtendedAction  DieBankBinningInfoActionCommand= DieBankBinningInfoActionCommandFactory.getActionCommand( action );
            if( DieBankBinningInfoActionCommand == null )
            {
                errors.put( "Invalid request", null );
            }
            else
            {
                actionForward = DieBankBinningInfoActionCommand.executeRequest( mapping, form, request, response );
            }
        }
        catch( Exception e )
        {
            e.printStackTrace();
            errors.put( ERROR_INTERNAL_SERVER_ERROR, "Error creating DieBankBinningInfoActionCommand Instance" );
        }
        request.setAttribute (SessionKeys.INFO_MESSAGES, info);
        request.setAttribute (SessionKeys.ERROR_MESSAGES, errors);
        return actionForward;
    }
}
